
namespace ShoppingCart.Business.Logic
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using ShoppingCart.Business.Entity;
    using ShoppingCart.DataAccess;

	/// <summary>
	/// Represents the Manager of Provincia.
	/// </summary>
	[Serializable]
	public class ProvinciaManager : Singleton<ProvinciaManager>
	{
		#region Methods

		/// <summary>
		/// Selects a single record from the Provincia table.
		/// </summary>
		public Provincia Obtener(int idProvincia)
		{
			try
			{
				return ProvinciaData.Instancia.Obtener(idProvincia);
			}
			catch (Exception) { throw; }
		}

		/// <summary>
		/// Selects all records from the Provincia table by a foreign key.
		/// </summary>
		public IList<Provincia> ListarPorIdDepartamento(int idDepartamento)
		{
			try
			{
				return ProvinciaData.Instancia.ListarPorIdDepartamento(idDepartamento);
			}
			catch (Exception) { throw; }
		}

        public IList<Provincia> ListarPorIdDepartamento(int idDepartamento, bool estado)
        {
            try
            {
                var provincias = ListarPorIdDepartamento(idDepartamento);
                return provincias.Where(p => p.Estado == estado).ToList();
            }
            catch (Exception) { throw; }
        }

		/// <summary>
		/// Saves a record to the Provincia table.
		/// </summary>
		public int Agregar(Provincia provincia)
		{
			try
			{
				return ProvinciaData.Instancia.Agregar(provincia);
			}
			catch (Exception) { throw; }
		}

		/// <summary>
		/// Updates a record in the Provincia table.
		/// </summary>
		public bool Modificar(Provincia provincia)
		{
			try
			{
				return ProvinciaData.Instancia.Modificar(provincia);
			}
			catch (Exception) { throw; }
		}

		/// <summary>
		/// Deletes a record from the Provincia table by its primary key.
		/// </summary>
		public bool Eliminar(int idProvincia)
		{
			try
			{
				return ProvinciaData.Instancia.Eliminar(idProvincia);
			}
			catch (Exception) { throw; }
		}

		/// <summary>
		/// Deletes a record from the Provincia table by a foreign key.
		/// </summary>
		public void EliminarPorIdDepartamento(int idDepartamento)
		{
			try
			{
				ProvinciaData.Instancia.EliminarPorIdDepartamento(idDepartamento);
			}
			catch (Exception) { throw; }
		}

		#endregion
	}
}
